package com.situ.user.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.user.bean.Address;

public interface AddressMapper {
	@Delete({ "delete from address", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into address (id, user_id, ", "province, city, ", "area, town, detail, ", "contact, phone)",
			"values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
			"#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, ",
			"#{area,jdbcType=VARCHAR}, #{town,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, ",
			"#{contact,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR})" })
	int insert(Address record);

	@Select({ "select", "id, user_id, province, city, area, town, detail, contact, phone", "from address",
			"where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
			@Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
			@Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
			@Result(column = "area", property = "area", jdbcType = JdbcType.VARCHAR),
			@Result(column = "town", property = "town", jdbcType = JdbcType.VARCHAR),
			@Result(column = "detail", property = "detail", jdbcType = JdbcType.VARCHAR),
			@Result(column = "contact", property = "contact", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR) })
	Address selectByPrimaryKey(Integer id);

	@Select({ "select", "id, user_id, province, city, area, town, detail, contact, phone", "from address" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
			@Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
			@Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
			@Result(column = "area", property = "area", jdbcType = JdbcType.VARCHAR),
			@Result(column = "town", property = "town", jdbcType = JdbcType.VARCHAR),
			@Result(column = "detail", property = "detail", jdbcType = JdbcType.VARCHAR),
			@Result(column = "contact", property = "contact", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR) })
	List<Address> selectAll();

	@Update({ "update address", "set user_id = #{userId,jdbcType=INTEGER},", "province = #{province,jdbcType=VARCHAR},",
			"city = #{city,jdbcType=VARCHAR},", "area = #{area,jdbcType=VARCHAR},", "town = #{town,jdbcType=VARCHAR},",
			"detail = #{detail,jdbcType=VARCHAR},", "contact = #{contact,jdbcType=VARCHAR},",
			"phone = #{phone,jdbcType=VARCHAR}", "where id = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(Address record);

	@Select({ "select * from address where user_id = #{userId}" })
	List<Address> selectByUserId(Integer userId);
}